package com.ecoolex.discount.sales.enums;

import com.ecoolex.discount.sales.entity.YouWorldGiftCard;
import com.ecoolex.framework.common.EnumInterface;
import com.ecoolex.framework.common.util.Assert;
import com.ecoolex.framework.common.util.Check;

public enum DiscountProductRechargeCounterPriceType implements EnumInterface<DiscountProductRechargeCounterPriceType, Integer> {
    FIXED(1, "固定"),
    VARIABLE(2, "可变"),
    ;

    private int real;

    private String describe;

    private DiscountProductRechargeCounterPriceType(int real, String describe) {
        this.real = real;
        this.describe = describe;
    }

    @Override
    public Integer real() {
        return real;
    }

    @Override
    public String describe() {
        return describe;
    }

    public static DiscountProductRechargeCounterPriceType realValueOf(Integer real) {
        if (Check.notNull(real)) {
            for (DiscountProductRechargeCounterPriceType v : values()) {
                if (v.real().equals(real)) {
                    return v;
                }
            }
        }
        return null;
    }

    public static DiscountProductRechargeCounterPriceType getCounterPriceType(YouWorldGiftCard youWorldGiftCard) {
        if ("variable".equalsIgnoreCase(youWorldGiftCard.getCardValueType())) {
            Assert.isTrue(Check.notNull(youWorldGiftCard.getCardMinValue()), "由我礼品卡数据异常,可变范围最小金额不存在");
            Assert.isTrue(Check.notNull(youWorldGiftCard.getCardMaxValue()), "由我礼品卡数据异常,可变范围最大金额不存在");
            return VARIABLE;
        } else {
            Assert.isTrue(Check.notNull(youWorldGiftCard.getFaceValue()), "由我礼品卡数据异常,固定金额不存在");
            return FIXED;
        }
    }
}
